<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('发运订单')"/>
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <div class="row">
        <div class="col-sm-12 select-table table-striped">
            <input type="hidden" id="id" name="id" th:value="${id}">
            <table id="bootstrap-tree-table"></table>
        </div>
    </div>
</div>
<div class="row">
    <div class="col-sm-offset-5 col-sm-10">
        <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>发 运</button>&nbsp;
        <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: bootstrap-fileinput-js"/>
<script th:inline="javascript">

    function submitHandler() {
        var id = $("#id").val();
        table.set();
        $.modal.confirm("确认信息无误！", function() {
            var url = prefix + "/updateOrderType";
            var data = {"ids": id};
            $.operate.submit(url, "post", "json", data);
        })
        closeItem();
        var parent = activeWindow();//关闭并调用父窗口刷新方法
        parent.fatherReload();
    }

    var prefix = ctx + "system/order"
    var prefix2 = ctx + "system/transfer"
    var datasPay = [[${@dict.getType('pay_type')}]];
    var datasType = [[${@dict.getType('order_type')}]];
    var renewFlag = [[${@permission.hasPermi('system:order:renew')}]];
    var addFlag = [[${@permission.hasPermi('system:transfer:add')}]];
    var editFlag = [[${@permission.hasPermi('system:transfer:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:transfer:remove')}]];

    $(function () {
        var options = {
            data: [[${orderList}]],
            renewUrl: prefix + "/renew/{id}",
            createUrl: prefix2 + "/add/{id}",
            updateUrl: prefix2 + "/edit/{id}",
            removeUrl: prefix2 + "/remove",
            id: "bootstrap-tree-table",
            code: "id",
            parentCode: "parentId",
            uniqueId: "id",
            modalName: "运单",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            columns: [
                {
                    field: 'selectItem',
                    radio: false
                },
                {
                    field: 'createUser',
                    title: '建单人',
                    formatter: function (value, row, index) {
                        if ($.common.isEmpty(row.icon)) {
                            if (row.userId != 1000) {
                                return '<span style="font-size: 15px;font-weight: bold;">' + row.createUser + '</span>';
                            }
                        } else {
                            return '<i class="' + row.icon + '"></i> <span class="nav-label" style="font-size: 15px;font-weight: bold;">' + row.createUser + '</span>';
                        }
                    }
                },
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    //field: 'vehicleInspector',
                    title: '提验人',
                    formatter: function (value, row, index) {
                        if (row.userId == 1000) {
                            return '<a >中转地：</a>' + row.vehicleInspector;
                        } else {
                            return '<span style="font-size: 15px;font-weight: bold;">' + row.vehicleInspector + '</span>';
                        }
                    }
                },
                {
                    // field: 'userName',
                    title: '业务员',
                    formatter: function (value, row, index) {
                        if (row.userId != 1000) {
                            // return row.userName;
                            return '<span style="font-size: 15px;font-weight: bold;">' + row.userName + '</span>';
                        }
                    }
                },
                {
                    // field: 'client',
                    title: '委托人',
                    formatter: function (value, row, index) {
                        if (row.userId == 1000) {
                            return '<a >中转费：</a>' + row.vin;
                        } else {
                            return '<span style="font-size: 15px;font-weight: bold;">' + row.client + '</span>';
                        }
                    }
                },
                {
                    field: 'clientPhone',
                    title: '委托人电话',
                    formatter: function (value, row, index) {
                        if (row.userId != 1000) {
                            return '<span style="font-size: 15px;font-weight: bold;">' + row.clientPhone + '</span>';
                        }
                    }
                },
                {
                    // field: 'vehicleModel',
                    title: '车型',
                    formatter: function (value, row, index) {
                        if (row.userId == 1000) {
                            return '<a >中转人：</a>' + row.vehicleModel;
                        } else {
                            // return row.vehicleModel;
                            return '<span style="font-size: 15px;font-weight: bold;">' + row.vehicleModel + '</span>';
                        }
                    }
                },
                {
                    field: 'vin',
                    title: '车架号',
                    formatter: function (value, row, index) {
                        if (row.userId != 1000) {
                            // return row.vin;
                            return '<span style="font-size: 15px;font-weight: bold;">' + row.vin + '</span>';
                        }
                    }
                },
                {
                    field: 'origin',
                    title: '起始地',
                    formatter: function (value, row, index) {
                        if (row.userId == 1000) {
                            return '<a >到收款：</a>' + row.client;
                        } else {
                            return '<span style="font-size: 15px;font-weight: bold;">' + row.origin + '</span>';
                        }
                    }
                },
                {
                    field: 'dest',
                    title: '目的地',
                    formatter: function (value, row, index) {
                        if (row.userId != 1000) {
                            return '<span style="font-size: 15px;font-weight: bold;">' + row.dest + '</span>';
                        }
                    }
                },
                {
                    field: 'receiverPhone',
                    title: '接车人电话',
                    formatter: function (value, row, index) {
                        if (row.userId == 1000) {
                            return '<a >欠/返：</a>' + row.clientPhone;
                        } else {
                            return '<span style="font-size: 15px;font-weight: bold;">' + row.receiverPhone + '</span>';
                        }
                    }
                    // formatter: function (value, row, index) {
                    //     if (row.userId != 1000) {
                    //         return '<span style="font-size: 15px;font-weight: bold;">' + row.receiverPhone + '</span>';
                    //     }
                    // }
                },
                {
                    field: 'freightAmount',
                    title: '运费金额',
                    formatter: function (value, row, index) {
                        if (row.userId != 1000) {
                            return '<span style="font-size: 15px;font-weight: bold;">' + row.freightAmount + '</span>';
                        }
                    }
                },
                {
                    field: 'paidAmount',
                    title: '预付款',
                    formatter: function (value, row, index) {
                        if (row.userId != 1000) {
                            return '<span style="font-size: 15px;font-weight: bold;">' + row.paidAmount + '</span>';
                        }
                    }
                },
                {
                    // field: 'payType',
                    title: '支付方式',
                    align: 'center',
                    formatter: function (value, row, index) {
                        if (row.userId == 1000) {
                            return '<a >备注：</a>' + row.origin;
                        } else {
                            return $.table.selectDictLabel(datasPay, row.payType);
                        }
                    }
                },
                {
                    field: 'orderType',
                    title: '订单状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(datasType, value);
                    }
                },
                {
                    field: 'createTime',
                    title: '建单时间',
                    formatter: function (value, row, index) {
                        if (row.userId != 1000) {
                            return '<span style="font-size: 15px;font-weight: bold;">' + row.createTime + '</span>';
                        }
                    }
                },
                // {
                //     field: 'otherFee',
                //     title: '其他费',
                //     align: 'center',
                //     formatter: function (value, row, index) {
                //         var itext = $.common.sprintf("<input class='form-control' type='text' id='otherFee' name='otherFee' value='" + value + "' onchange='submitOtherFee(" + row.id + ")' style='width: 80px;'>", $.table.serialNumber(index));
                //         return itext;
                //     }
                // },
                {
                    field: 'notes',
                    title: '备注',
                    formatter: function (value, row, index) {
                        if (row.userId != 1000) {
                            return '<span style="font-size: 15px;font-weight: bold;">' + row.notes + '</span>';
                        }
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (row.userId != 1000) {
                            actions.push('<a class="btn btn-info btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="$.operate.add(\'' + row.id + '\')"><i class="fa fa-plus"></i>添加中转</a> ');
                            actions.push('<a class="btn btn-success btn-xs ' + renewFlag + '" href="javascript:void(0)" onclick="$.operate.renewFull(\'' + row.id + '\')"><i class="fa fa-edit"></i>详单</a> ');
                        } else {
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        }
                        return actions.join('');
                    }
                }]
        };
        $.treeTable.init(options);
    });

    function remove(id) {
        table.set();
        $.modal.confirm("确定删除该条信息吗？", function() {
            var url = prefix2 + "/remove";
            var data = { "ids": id };
            $.operate.submit(url, "post", "json", data);
            setTimeout( function(){
                window.location.reload();
            }, 500 );
        });
    }
    function reload() {
        window.location.reload();
    }
</script>
</body>
</html>